import json

from .getPublicData import *
from myApp.models import JobInfo

def getPageData():
    return hotCity

def getSalaryData(defaultCity):
    jobs = JobInfo.objects.filter(address=defaultCity)
    salaries = []
    for i in jobs:
        if i.internship == '0':
            salaries.append(json.loads(i.salary)[1])
    salaryColumn = [0 for x in range(len(salaryList))]
    for i in salaries:
        s = i / 1000
        if s < 10:
            salaryColumn[0] += 1
        elif 10 <= s and s <= 20:
            salaryColumn[1] += 1
        elif 20 <= s and s <= 30:
            salaryColumn[2] += 1
        elif 30 <= s and s <= 40:
            salaryColumn[3] += 1
        else:
            salaryColumn[4] += 1
    return salaryList,salaryColumn

def getCompanyPeopleData(defaultCity):
    jobs = JobInfo.objects.filter(address=defaultCity)
    people = []
    for i in jobs:
        people.append(json.loads(i.companyPeople)[1])
    peopleColumn = [0 for x in range(len(companyPeople))]
    for p in people:
        if p < 20:
            peopleColumn[0] += 1
        elif p <= 100:
            peopleColumn[1] += 1
        elif p <= 500:
            peopleColumn[2] += 1
        elif p <= 1000:
            peopleColumn[3] += 1
        elif p < 10000:
            peopleColumn[4] += 1
        else:
            peopleColumn[5] += 1
    result = []
    for index, item in enumerate(peopleColumn):
        result.append({
            'name': companyPeople[index],
            'value': item
        })
    return result

def getEducationData(defaultCity):
    jobs = JobInfo.objects.filter(address=defaultCity)
    educationData = {}
    for i in jobs:
        if educationData.get(i.educational, -1) == -1:
            educationData[i.educational] = 1
        else:
            educationData[i.educational] += 1
    result = []
    for k,v in educationData.items():
        result.append({
            'name': k,
            'value': v
        })
    return result

def getDistData(defaultCity):
    jobs = JobInfo.objects.filter(address=defaultCity)
    distData = {}
    for job in jobs:
        if job.dist != '' and job.dist != 'nan':
            if distData.get(job.dist,-1) == -1:
                distData[job.dist] = 1
            else:
                distData[job.dist] += 1
    result = []
    for k, v in distData.items():
        result.append({
            "name": k,
            'value': v
        })
    return result